/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rpt.bd.cenario;

import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;

/**
 *
 * @author Roberto
 */
public class CGradeBd extends CGrade {

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    protected CPersistenciaBd fPersistenciaBd;

    //DefaultTableModel fModeloGrade = null;

    public CGradeBd(
            final CPersistenciaBd aPertinenciaBd, final boolean aPreparar) {
        super(false);
        fPersistenciaBd = aPertinenciaBd;
        fConjuntoDadosBd = fPersistenciaBd.getConjuntoDadosBd();
        preparar(aPreparar);
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    @Override
    public void eventoSelecionar(
            final ListSelectionEvent event) {
        if (event.getValueIsAdjusting()) return;
        int vLinhaAtual = getSelectedRow();
        if (vLinhaAtual >= 0) {
            setRegistroBdAtual(vLinhaAtual);
        }
        if (getRegistroBdLinhaAtual() < 0) return;
        int vNumColunasVisiveis = getColumnCount();
        Object o = getRegistroBdAtual().get(vNumColunasVisiveis-1); //getValueAt(vNumLinha,vNumColunasVisiveis);
        if (o == null) {
            CDadosComplementaresRegistroBd x = new CDadosComplementaresRegistroBd();
        } else {
            getRegistroBdAtual().atualizarPainelBd(false);
            if (o instanceof String) {
                String s = (String)o;
            }
        }
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    @Override
    protected void changeSelectionModel( 
            final ListSelectionModel sm, final int index,
            final boolean toggle, final boolean extend, final boolean selected )
    {
        EStatusOperacao s = fPersistenciaBd.getStatusOperacao();
        if (s != EStatusOperacao.consulta) {
            return;
        }
        super.changeSelectionModel(sm, index, toggle, extend, selected);
    }

    /**
     * Overites same method in the JTable that was doing the scrollToRect for the selected cell.
     * Not it does scrollToRect for the selected row.
     */

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    @Override
    public void changeSelection( 
            final int rowIndex, final int columnIndex, 
            final boolean toggle, final boolean extend )
    {
        EStatusOperacao s = fPersistenciaBd.getStatusOperacao();
        if (s != EStatusOperacao.consulta) {
            return;
        }
        super.changeSelection(rowIndex,columnIndex,toggle,extend);
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    @Override
    protected int getNumCamposCabecalhoBd() {
        return fPersistenciaBd.getNumCamposCabecalhoBd();
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    @Override
    protected CEstruturaRegistroBd getEstruturaRegistroBd() {
        return fPersistenciaBd.getEstruturaRegistroBd();
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    @Override
    public CConjuntoDadosBd getConjuntoDadosBd() {
        return fPersistenciaBd.getConjuntoDadosBd();
    }
}
